from rest_framework.views import exception_handler
from rest_framework.response import Response


def MyExceptionHandler(exc, context):
    # Call REST framework's default exception handler first,
    # to get the standard error response.
    response = exception_handler(exc, context)

    # Now add the HTTP status code to the response.
    if response is not None:
            response.data['status_code'] = response.status_code
    else:
        response = Response(data={'detail': 'Internal Server Error', 'status': 500, 'error': str(exc)}, status=500)
    return response
